package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.minorDefectsRecordPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName:minorDefectsRecordMapp
 * Package:com.example.mapper
 * Description:
 *
 * @Author：牧星苑
 * @Create 2025/10/7 14:24
 * @Version 1.0
 */
@Mapper
public interface minorDefectsRecordMapp {
    //插入一行微小缺陷
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_minor_defects_record (" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "team, raised_by, date, " +
            "workshop, line, op, " +
            "equipment_number, defect_description, countermeasure_content, " +
            "spare_parts_information, responsible_person, completion_date, " +
            "countermeasure_effectiveness, confirmed_by, closing, " +
            "reporting) " +
            "values (" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{team}, #{raised_by}, #{date}, " +
            "#{workshop}, #{line}, #{op}, " +
            "#{equipment_number}, #{defect_description}, #{countermeasure_content}, " +
            "#{spare_parts_information}, #{responsible_person}, #{completion_date}, " +
            "#{countermeasure_effectiveness}, #{confirmed_by}, #{closing}, " +
            "#{reporting})")
    void insertOne(minorDefectsRecordPojo pojo);

    //修改一行微小缺陷
    @DS("newMscLowCodeFormal")
    //更新哪些字段的数据
    @Update("update ddm_minor_defects_record " +
            "set " +
            "update_time=#{update_time}, " +
            "creator=#{creator}, " +
            "process_status=#{process_status}, " +
            "sys_update_user=#{sys_update_user}, "+
            "sys_audit_user=#{sys_audit_user}, " +
            "sys_audit_time=#{sys_audit_time}, " +
            "sys_deleted=#{sys_deleted}," +
            "team=#{team}, " +
            "raised_by=#{raised_by}, " +
            "date=#{date}, " +
            "workshop=#{workshop}, " +
            "line=#{line}, " +
            "op=#{op}, " +
            "equipment_number=#{equipment_number},  " +
            "defect_description=#{defect_description}, " +
            "countermeasure_content=#{countermeasure_content}, " +
            "spare_parts_information=#{spare_parts_information}, " +
            "responsible_person=#{responsible_person}, " +
            "completion_date=#{completion_date}, " +
            "countermeasure_effectiveness=#{countermeasure_effectiveness}, " +
            "confirmed_by=#{confirmed_by}, " +
            "closing=#{closing}, " +
            "reporting=#{reporting} " +
            "where id=#{id}")
    void editOneById(minorDefectsRecordPojo pojo);

    //根据分页查询微小缺陷数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_minor_defects_record where " +
            "workshop=#{workshop} and sys_deleted=0 " +
            "order by date DESC " +
            "limit #{startRow}, #{size}")
    List<minorDefectsRecordPojo> queryByPage(Integer startRow, Integer size, String workshop);

    //查询所有微小缺陷条数
    @DS("newMscLowCodeFormal")
    @Select("SELECT COUNT(*) FROM ddm_minor_defects_record where workshop=#{workshop} and sys_deleted=0")
    Integer queryQuantity(String workshop);
}
